package com.anyi.gulimall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.anyi.gulimall.common.utils.PageUtils;
import com.anyi.gulimall.common.utils.Query;

import com.anyi.gulimall.ware.dao.WmsPurchaseDetailDao;
import com.anyi.gulimall.ware.entity.WmsPurchaseDetailEntity;
import com.anyi.gulimall.ware.service.WmsPurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("wmsPurchaseDetailService")
public class WmsPurchaseDetailServiceImpl extends ServiceImpl<WmsPurchaseDetailDao, WmsPurchaseDetailEntity> implements WmsPurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        /**
         *    添加额外检索信息
         *    key: '华为',//检索关键字
         *    status: 0,//状态
         *    wareId: 1,//仓库id
         */
        LambdaQueryWrapper<WmsPurchaseDetailEntity> wrapper = new LambdaQueryWrapper<>();
        String  key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.and(obj->{
                obj.eq(WmsPurchaseDetailEntity::getId,key).or().like(WmsPurchaseDetailEntity::getPurchaseId,key);
            });
        }

        String  status = (String) params.get("status");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq(WmsPurchaseDetailEntity::getStatus,Integer.parseInt(status));
        }

        String wareId = (String) params.get("wareId");
        if (!StringUtils.isEmpty(wareId)){
            wrapper.eq(WmsPurchaseDetailEntity::getWareId,Long.parseLong(wareId));
        }

        IPage<WmsPurchaseDetailEntity> page = this.page(
                new Query<WmsPurchaseDetailEntity>().getPage(params),
                wrapper

        );

        return new PageUtils(page);
    }

}